package cn.micro.keep.accounts.controller;


import cn.micro.keep.accounts.api.Page;
import cn.micro.keep.accounts.api.Result;
import cn.micro.keep.accounts.common.utils.SecurityUtil;
import cn.micro.keep.accounts.entity.dto.AccountOdsRecordDTO;
import cn.micro.keep.accounts.entity.dto.AccountOdsRecordSearch;
import cn.micro.keep.accounts.entity.dto.PieChartSearch;
import cn.micro.keep.accounts.service.AccountOdsRecordImgService;
import cn.micro.keep.accounts.service.AccountOdsRecordService;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 账单信息表 前端控制器
 * </p>
 *
 * @author 柘阳科技
 * @since 2023-11-08
 */
@RestController
@RequestMapping("/accounts/accountDimRecord")
@RequiredArgsConstructor
@Validated
public class AccountOdsRecordController {

    private final AccountOdsRecordService accountOdsRecordService;


    /**
     * 获取用户账单明细列表
     * @param search
     * @return
     */
    @GetMapping("listByUser")
    public Object listByUser(AccountOdsRecordSearch search){
        search.setUserId(SecurityUtil.getUserId());
        return new Result<>().success(new PageInfo<>(accountOdsRecordService.listByUser(search)));
    }

    /**
     * 获取账单明细信息
     * @param id
     * @return
     */
    @GetMapping("info/{id}")
    public Object info(@PathVariable("id") Long id){
        return new Result<>().success(accountOdsRecordService.info(id));
    }

    /**
     * 创建账单记录
     * @param dto
     * @return
     */
    @PostMapping("create")
    public Object create(@Validated @RequestBody AccountOdsRecordDTO dto){
        if (!accountOdsRecordService.create(dto)){
            return new Result<>().fail();
        }
        return new Result<>().success();
    }


    /**
     * 删除记录信息
     * @param id
     * @return
     */
    @DeleteMapping("delete/{id}")
    public Object delete(@PathVariable Long id){
        if (!accountOdsRecordService.deleteRecord(id)){
            return new Result<>().fail();
        }
        return new Result<>().success();
    }


    /**
     * 昨日统计信息
     * @return
     */
    @GetMapping("yesterdayStatistics")
    public Object yesterdayStatistics(){
        return new Result<>().success(accountOdsRecordService.yesterdayStatistics());
    }


    @GetMapping("todayList")
    public Object todayList(Page page){
        return new Result<>().success();
    }

    /**
     * 用户今日账单统计信息
     * 记录数，金额，收入，支出，收入支出比例，收入支出排行，按照类型区分，按照标签区分
     * 饼图--收入支出比例，折线图--收入支出排行  饼图--具体支出
     * @return
     */
    @GetMapping("commonStatToday")
    public Object commonStatToday(){
        return new Result<>().success();
    }

    @GetMapping("pieChart")
    public Object pieChart(PieChartSearch search){
        return new Result<>().success(accountOdsRecordService.pieChart(search));
    }


}
